package Thread;

import java.util.concurrent.*;

public class TestThread3 implements Callable<String> {
    String name;
    @Override
    public String call() throws Exception {
        if(this.getName().equals("task1")){
            return "thread1";
        }else if(this.getName().equals("task2")){
            return "thread2";
        }else{
            return "thread3";
        }
    }

    TestThread3(String name){
        this.name = name;
    }

    public String getName(){
        return name;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        TestThread3 task1 = new TestThread3("task1");
        TestThread3 task2 = new TestThread3("task2");
        TestThread3 task3 = new TestThread3("task3");

        ExecutorService service = Executors.newFixedThreadPool(3);

        Future<String> r1 = service.submit(task1);
        Future<String> r2 = service.submit(task2);
        Future<String> r3 = service.submit(task3);

        String s1 = r1.get();
        String s2 = r2.get();
        String s3 = r3.get();

        System.out.println(s1+","+s2+","+s3);

        service.shutdown();
    }
}
